package cn.itcast.type;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;

import java.util.ArrayList;
import java.util.List;

public class ProducerBatch {
    public static void main(String[] args) throws Exception {
        // 1. 谁来发?
        DefaultMQProducer producer = new DefaultMQProducer("group1");

        // 2. 发给谁?
        producer.setNamesrvAddr("127.0.0.1:9876");
        producer.start();

        // 3. 怎么发？
        // 4. 发什么?
        List<Message> messageList = new ArrayList<>();
        Message message1 = new Message("topic1", "hello world 1".getBytes());
        Message message2 = new Message("topic1", "hello world 2".getBytes());
        Message message3 = new Message("topic1", "hello world 3".getBytes());
        messageList.add(message1);
        messageList.add(message2);
        messageList.add(message3);
        // 批量发送
        producer.send(messageList);
        // 5. 打扫战场？
        producer.shutdown();
    }
}
